#ifndef SQLCONTROLLER_H
#define SQLCONTROLLER_H


#include <QSqlDatabase>
#include <QSqlQueryModel>
#include "config.h"
#include <QSqlRelationalTableModel>
#include <QSqlTableModel>
#include "usermanagement.h"
class SqlController
{
public:
    SqlController();

    static SqlController *getSqlController();

    bool initDataBase();
    bool removeUser(QString name);
    bool goRegister(QString name,QString pwd,int auth=0);
    bool goLogin(QString name,QString pwd,int auth);
    bool removeUser(int id);
    //用户界面接口
    QSqlRelationalTableModel* getModel();//获取数据
    void outletnum(int id, int num);//出库
    //增删改查接口
    //添加
    bool addproduct(ProductInfo pro);
    //修改
    bool updateProduct(ProductInfo pro,int id);
    //查找
    QSqlRelationalTableModel* selectProduct();

    QString strToMd5(QString str);


    QSqlTableModel *getModelUserManage();

    int prodectNum() const;
    void setProdectNum(int newProdectNum);


//用户id
    int getUser_id() const;
    void setUser_id(int newUser_id);

    //获取商品结构体
    const ProductInfo& getTempPro() const;
    void setTempPro(const ProductInfo &newTempPro);

    //名字查询
    void setName(QString str);

private:
    static SqlController *s_instance;
    QSqlDatabase m_db;
    int m_prodectNum;//数值
    ProductInfo tempPro;
    int user_id;
    QString name;
};

#endif // SQLCONTROLLER_H
